home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / msysjour / vol07 / 02 / controls / msapi.c < prev    next >
C/C++ Source or Header  |  1992-02-29  |  11KB  |  411 lines

  1. /*
  2.  * MSAPI.C
  3.  *
  4.  * Contains the API implementation of the MicroScroll custom
  5.  * control, including functional messages and function message
  6.  * equivalents.
  7.  *
  8.  * Version 1.1, October 1991, Kraig Brockschmidt
  9.  */
  10.  
  11.  
  12. #include <windows.h>
  13. #include "muscrdll.h"
  14.  
  15.  
  16. /*
  17.  * LMicroScrollAPI
  18.  *
  19.  * Purpose:
  20.  *  Processes any control-specific function messages for the
  21.  *  MicroScroll control.
  22.  *
  23.  * Parameters:
  24.  *  hWnd            HWND handle to the control window.
  25.  *  iMsg            WORD message identifier.
  26.  *  wParam          WORD parameter of the message.
  27.  *  lParam          LONG parameter of the message.
  28.  *  pMS             PMUSCROLL pointer to control-specific data.
  29.  *
  30.  * Return Value:
  31.  *  LONG            Varies with the message.
  32.  *
  33.  */
  34.  
  35.  
  36.  
  37. LONG PASCAL LMicroScrollAPI(HWND hWnd, WORD iMsg, WORD wParam,
  38.                             LONG lParam, PMUSCROLL pMS)
  39.     {
  40.     DWORD           dwT;
  41.     COLORREF        cr;
  42.     HWND            hWndT;
  43.     WORD            iMin, iMax;
  44.     WORD            iPos;
  45.     WORD            wID;
  46.  
  47.     switch (iMsg)
  48.         {
  49.         case MSM_HWNDASSOCIATESET:
  50.             //Change the associate window of this control.
  51.             if (!IsWindow((HWND)wParam))
  52.                 return -1;
  53.  
  54.             //Save old window handle.
  55.             hWndT=pMS->hWndAssociate;
  56.  
  57.             //Get our ID value, then send WM_COMMAND notifications.
  58.             wID=GetWindowWord(hWnd, GWW_ID);
  59.  
  60.             SendMessage(hWndT, WM_COMMAND, wID,
  61.                         MAKELONG(hWnd, MSN_ASSOCIATELOSS));
  62.  
  63.             pMS->hWndAssociate=(HWND)wParam;
  64.  
  65.             SendMessage(pMS->hWndAssociate, WM_COMMAND, wID,
  66.                         MAKELONG(hWnd, MSN_ASSOCIATEGAIN));
  67.  
  68.             return MAKELONG(hWndT, 0);
  69.  
  70.  
  71.         case MSM_HWNDASSOCIATEGET:
  72.             return MAKELONG(pMS->hWndAssociate, 0);
  73.  
  74.  
  75.         case MSM_DWRANGESET:
  76.             /*
  77.              * Set the new range, sending the appropriate notifications.
  78.              * Also send a scroll message if the position has to change.
  79.              * If the minimum is greater than the max, return error.
  80.              */
  81.             if (LOWORD(lParam) >= HIWORD(lParam))
  82.                 return -1L;
  83.  
  84.             wID=GetWindowWord(hWnd, GWW_ID);
  85.  
  86.             SendMessage(pMS->hWndAssociate, WM_COMMAND, wID,
  87.                         MAKELONG(hWnd, MSN_RANGECHANGE));
  88.  
  89.             //Save old values.
  90.             iMin=pMS->iMin;
  91.             iMax=pMS->iMax;
  92.  
  93.             pMS->iMin=LOWORD(lParam);
  94.             pMS->iMax=HIWORD(lParam);
  95.  
  96.             /*
  97.              * If current position is outside of new range, force it to
  98.              * the average of the range, otherwise leave it be.
  99.              */
  100.             if ((pMS->iMin >= pMS->iPos) ||
  101.                 (pMS->iMax <= pMS->iPos))
  102.                 {
  103.                 pMS->iPos=(pMS->iMin + pMS->iMax) >> 1;
  104.  
  105.                 //Send a scroll message if we change position.
  106.                 iMsg=(MSS_VERTICAL & pMS->dwStyle) ? WM_VSCROLL : WM_HSCROLL;
  107.                 wParam=SB_THUMBTRACK;
  108.                 lParam=MAKELONG(pMS->iPos, 0);
  109.  
  110.                 SendMessage(pMS->hWndAssociate, iMsg, wParam, lParam);
  111.                 }
  112.  
  113.             //Return old range.
  114.             return MAKELONG(iMin, iMax);
  115.  
  116.         case MSM_DWRANGEGET:
  117.             return MAKELONG(pMS->iMin, pMS->iMax);
  118.  
  119.  
  120.         case MSM_WCURRENTPOSSET:
  121.             /*
  122.              * Set the new position if it falls within the valid range,
  123.              * sending the appropriate scroll message.
  124.              */
  125.  
  126.             //Save current position
  127.             iPos=pMS->iPos;
  128.  
  129.             if ((pMS->iMin <= wParam) && (pMS->iMax >= wParam))
  130.                 {
  131.                 pMS->iPos=wParam;
  132.                 iMsg=(MSS_VERTICAL & pMS->dwStyle) ? WM_VSCROLL : WM_HSCROLL;
  133.                 wParam=SB_THUMBTRACK;
  134.                 lParam=MAKELONG(pMS->iPos, 0);
  135.  
  136.                 SendMessage(pMS->hWndAssociate, iMsg, wParam, lParam);
  137.  
  138.                 //Return old position.
  139.                 return MAKELONG(iPos, 0);
  140.                 }
  141.  
  142.             //Invalid position.
  143.             return -1;
  144.  
  145.         case MSM_WCURRENTPOSGET:
  146.             return MAKELONG(pMS->iPos, 0);
  147.  
  148.  
  149.         case MSM_FNOPEGSCROLLSET:
  150.             /*
  151.              * Set the MSS_NOPEGSCROLL style to the value in
  152.              * lParam which is zero or MSS_NOPEGSCROLL.
  153.              */
  154.             dwT=pMS->dwStyle & MSS_NOPEGSCROLL;
  155.  
  156.             //Either set of clear the style.
  157.             if ((BOOL)wParam)
  158.                 pMS->dwStyle |= MSS_NOPEGSCROLL;
  159.             else
  160.                 pMS->dwStyle &= ~MSS_NOPEGSCROLL;
  161.  
  162.             //Return TRUE or FALSE if the bit was or wasn't set
  163.             return (dwT ? 1L : 0L);
  164.  
  165.         case MSM_FNOPEGSCROLLGET:
  166.             return (pMS->dwStyle & MSS_NOPEGSCROLL);
  167.  
  168.  
  169.         case MSM_FINVERTRANGESET:
  170.             /*
  171.              * Set the MSS_INVERTRANGE style to the value in
  172.              * lParam which is zero or MSS_INVERTRANGE.
  173.              */
  174.             dwT=pMS->dwStyle & MSS_INVERTRANGE;
  175.  
  176.             //Either set of clear the style.
  177.             if ((BOOL)wParam)
  178.                 pMS->dwStyle |= MSS_INVERTRANGE;
  179.             else
  180.                 pMS->dwStyle &= ~MSS_INVERTRANGE;
  181.  
  182.             //Return TRUE or FALSE if the bit was or wasn't set
  183.             return (dwT ? 1L : 0L);
  184.  
  185.  
  186.         case MSM_FINVERTRANGEGET:
  187.             return (pMS->dwStyle & MSS_INVERTRANGE);
  188.  
  189.  
  190.         case MSM_CRCOLORSET:
  191.             if (wParam >= CCOLORS)
  192.                 return 0L;
  193.  
  194.             cr=pMS->rgCr[wParam];
  195.  
  196.             //If -1 is set in rgCr the paint procedure uses a default.
  197.             pMS->rgCr[wParam]=(COLORREF)lParam;
  198.  
  199.             //Force repaint since we changed a state.
  200.             InvalidateRect(hWnd, NULL, TRUE);
  201.             UpdateWindow(hWnd);
  202.  
  203.             //Return the old color.
  204.             return (LONG)cr;
  205.  
  206.         case MSM_CRCOLORGET:
  207.             if (wParam >= CCOLORS)
  208.                 return 0L;
  209.  
  210.             return (LONG)pMS->rgCr[wParam];
  211.         }
  212.     return 0L;
  213.     }
  214.  
  215.  
  216.  
  217.  
  218. /*
  219.  * Message API Functions
  220.  *
  221.  * The advantage of using a function instead of SendMessage is that
  222.  * you get type checking on the parameters and the return value.'
  223.  *
  224.  * Header comments are provided on these functions in pairs.  All
  225.  * functions take hWnd (control handle), and the Set functions
  226.  * usually take an extra paarameter containing the new value.
  227.  *
  228.  */
  229.  
  230.  
  231. /*
  232.  * MSHwndAssociateSet
  233.  * MSHwndAssociateGet
  234.  *
  235.  * Purpose:
  236.  *  Change or retrieve the associate window of the control.
  237.  *
  238.  * Parameters:
  239.  *  hWnd            HWND of the control window.
  240.  *
  241.  * Set Parameters:
  242.  *  hWndAssociate   HWND of new associate.
  243.  *
  244.  * Return Value:
  245.  *  HWND            Handle of previous associate (set) or current
  246.  *                  associate (set).
  247.  */
  248.  
  249. HWND FAR PASCAL MSHwndAssociateSet(HWND hWnd, HWND hWndAssociate)
  250.     {
  251.     return (HWND)SendMessage(hWnd, MSM_HWNDASSOCIATESET,
  252.                              (WORD)hWndAssociate, 0L);
  253.     }
  254.  
  255. HWND FAR PASCAL MSHwndAssociateGet(HWND hWnd)
  256.     {
  257.     return (HWND)SendMessage(hWnd, MSM_HWNDASSOCIATESET, 0, 0L);
  258.     }
  259.  
  260.  
  261. /*
  262.  * MSRangeSet
  263.  * MSRangeGet
  264.  *
  265.  * Purpose:
  266.  *  Change or retrieve the range of the control.
  267.  *
  268.  * Parameters:
  269.  *  hWnd            HWND of the control window.
  270.  *
  271.  * Set Parameters:
  272.  *  iMin            WORD new minimum of the range.
  273.  *  iMax            WORD new maximum of the range.
  274.  *
  275.  * Return Value:
  276.  *  DWORD           Low-order word contains the previous (set) or
  277.  *                  current (get) minimum, high-order word contains
  278.  *                  the previous or current maximum.
  279.  */
  280.  
  281. DWORD FAR PASCAL MSDwRangeSet(HWND hWnd, WORD iMin, WORD iMax)
  282.     {
  283.     return (DWORD)SendMessage(hWnd, MSM_DWRANGESET, 0, MAKELONG(iMin, iMax));
  284.     }
  285.  
  286. DWORD FAR PASCAL MSDwRangeGet(HWND hWnd)
  287.     {
  288.     return (DWORD)SendMessage(hWnd, MSM_DWRANGESET, 0, 0L);
  289.     }
  290.  
  291.  
  292. /*
  293.  * MSWCurrentPosSet
  294.  * MSWCurrentPosGet
  295.  *
  296.  * Purpose:
  297.  *  Change or retrieve the current position of the control.
  298.  *
  299.  * Parameters:
  300.  *  hWnd            HWND of the control window.
  301.  *
  302.  * Set Parameters:
  303.  *  iPos            WORD new position to set.
  304.  *
  305.  * Return Value:
  306.  *  WORD            Previous (set) or current (get) position.
  307.  *
  308.  */
  309.  
  310. WORD FAR PASCAL MSWCurrentPosSet(HWND hWnd, WORD iPos)
  311.     {
  312.     return (WORD)SendMessage(hWnd, MSM_WCURRENTPOSSET, iPos, 0L);
  313.     }
  314.  
  315. WORD FAR PASCAL MSWCurrentPosGet(HWND hWnd)
  316.     {
  317.     return (WORD)SendMessage(hWnd, MSM_WCURRENTPOSGET, 0, 0L);
  318.     }
  319.  
  320.  
  321.  
  322.  
  323. /*
  324.  * MSFNoPegScrollSet
  325.  * MSFNoPegScrollGet
  326.  *
  327.  * Purpose:
  328.  *  Change or retrieve the state of the MSS_NOPEGSCROLL style bit.
  329.  *
  330.  * Parameters:
  331.  *  hWnd            HWND of the control window.
  332.  *
  333.  * Set Parameters:
  334.  *  fNoPegScroll    BOOL flag to set (TRUE) or clear (FALSE) the style.
  335.  *
  336.  * Return Value:
  337.  *  BOOL            Previous (set) or current (get) state of this
  338.  *                  style bit, either TRUE for on, FALSE for off.
  339.  */
  340.  
  341. BOOL FAR PASCAL MSFNoPegScrollSet(HWND hWnd, BOOL fNoPegScroll)
  342.     {
  343.     return (BOOL)SendMessage(hWnd, MSM_FNOPEGSCROLLSET, fNoPegScroll, 0L);
  344.     }
  345.  
  346. BOOL FAR PASCAL MSFNoPegScrollGet(HWND hWnd)
  347.     {
  348.     return (BOOL)SendMessage(hWnd, MSM_FNOPEGSCROLLGET, 0, 0L);
  349.     }
  350.  
  351.  
  352.  
  353. /*
  354.  * MSFInvertRangeSet
  355.  * MSFInvertRangeGet
  356.  *
  357.  * Purpose:
  358.  *  Change or retrieve the state of the MSS_INVERTRANGE style bit.
  359.  *
  360.  * Parameters:
  361.  *  hWnd            HWND of the control window.
  362.  *
  363.  * Set Parameters:
  364.  *  fInvertRange    BOOL flag to set (TRUE) or clear (FALSE) the style.
  365.  *
  366.  * Return Value:
  367.  *  BOOL            Previous (set) or current (get) state of this
  368.  *                  style bit, either TRUE for on, FALSE for off.
  369.  */
  370.  
  371. BOOL FAR PASCAL MSFInvertRangeSet(HWND hWnd, BOOL fInvertRange)
  372.     {
  373.     return (BOOL)SendMessage(hWnd, MSM_FINVERTRANGESET, fInvertRange, 0L);
  374.     }
  375.  
  376. BOOL FAR PASCAL MSFInvertRangeGet(HWND hWnd)
  377.     {
  378.     return (BOOL)SendMessage(hWnd, MSM_FINVERTRANGEGET, 0, 0L);
  379.     }
  380.  
  381.  
  382.  
  383. /*
  384.  * MSCrColorSet
  385.  * MSCrColorGet
  386.  *
  387.  * Purpose:
  388.  *  Change or retrieve a configurable color.
  389.  *
  390.  * Parameters:
  391.  *  hWnd            HWND of the control window.
  392.  *  iColor          WORD index to the control to modify or retrieve.
  393.  *
  394.  * Set Parameters:
  395.  *  cr              COLORREF new value of the color.
  396.  *
  397.  * Return Value:
  398.  *  COLORREF        Previous (set) or current (get) color value.
  399.  *
  400.  */
  401.  
  402. COLORREF FAR PASCAL MSCrColorSet(HWND hWnd, WORD iColor, COLORREF cr)
  403.     {
  404.     return (BOOL)SendMessage(hWnd, MSM_CRCOLORSET, iColor, (LONG)cr);
  405.     }
  406.  
  407. COLORREF FAR PASCAL MSCrColorGet(HWND hWnd, WORD iColor)
  408.     {
  409.     return (COLORREF)SendMessage(hWnd, MSM_CRCOLORGET, iColor, 0L);
  410.     }
  411.